
//
// 101128 - AH - Created.
//

package org.soekrat.gui.swing.resource;

import java.awt.Component;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 * <p>
 *   Uriliry method to create
 *   {@link Component} to show a resource value.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public class ResourceValueComponentFactory 
{
  // Utility pattern dictates private constructor.
  private ResourceValueComponentFactory(){}
  
  /**
   * <p>
   *   Creates 
   *   {@link Component} to show resource value.
   * </p>
   * @param value Value to show.
   * @return {@link Component} that shows {@code value}.
   */
  public static Component create(Object value)
  {
    value=(value==null) ? "No value" : value;
    
    if (value instanceof Image)
    {
      return new JLabel(new ImageIcon((Image)value));
    }
    else
    {
      JTextField retVal=new JTextField(15);
      retVal.setEditable(false);
      retVal.setText(value.toString());
      return retVal;
    }
  }
  
}
